package de.bazinga.rotw.effects;

import com.jme.light.LightNode;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jmex.effects.LensFlare;
import com.jmex.effects.LensFlareFactory;

import de.bazinga.rotw.texture.TextureCache;


public class LensFlareEffects {
	private LightNode lightNode;
	private LensFlare flare;
	
	public LensFlareEffects(LightState lightState,Node rootNode, Vector3f location) {
		TextureState[] tex = {TextureCache.getInstance().getTexture("texture/flare1.png"),
				TextureCache.getInstance().getTexture("texture/flare2.png"),
				TextureCache.getInstance().getTexture("texture/flare3.png"),
				TextureCache.getInstance().getTexture("texture/flare4.png")
		};
		
		flare = LensFlareFactory.createBasicLensFlare("flare", tex);
        flare.setRootNode(rootNode);
        
        
        PointLight dr = new PointLight();
        dr.setEnabled(true);
        dr.setDiffuse(ColorRGBA.white.clone());
        dr.setAmbient(ColorRGBA.gray.clone());
        dr.setLocation(new Vector3f(0f, 0f, 0f));

        lightState.attach(dr);
        lightState.setTwoSidedLighting(true);

        lightNode = new LightNode("light");
        lightNode.setLight(dr);

       
        lightNode.setLocalTranslation(location);
        

        rootNode.attachChild(lightNode);

        // notice that it comes at the end
        lightNode.attachChild(flare);
	}
}
